# 作用是把在同一文件夹的xml和img分在2个文件夹里
import os
import shutil
from tqdm import tqdm

# Set the source directory
src_dir = 'F:\\items\\bike-model\\搜集的数据集\\解压后\\archive(1)\\dataset\\Bicycle annotated'

# Set the destination directories for XML and JPG files
xml_dest_dir = 'F:\\items\\bike-model\\搜集的数据集\\解压后\\archive(1)\\dataset\\Annotations'
jpg_dest_dir = 'F:\\items\\bike-model\\搜集的数据集\\解压后\\archive(1)\\dataset\\JPEGImages'

# Create the destination directories if they don't exist
os.makedirs(xml_dest_dir, exist_ok=True)
os.makedirs(jpg_dest_dir, exist_ok=True)

# Iterate over the files in the source directory
for filename in tqdm(os.listdir(src_dir)):
    # Get the full path of the file
    file_path = os.path.join(src_dir, filename)

    # Check if the file is an XML or JPG file
    if filename.endswith('.xml'):
        # Move the XML file to the XML destination directory
        shutil.move(file_path, xml_dest_dir)
    elif filename.endswith('.jpg'):
        # Move the JPG file to the JPG destination directory
        shutil.move(file_path, jpg_dest_dir)
